/**
 * 
 */
package org.abettor.smartswt.util;

import java.lang.reflect.Field;

/**
 * 获取静态常量的工具类
 * @author abettor
 *
 */
public class StaticProperty
{
	//	私有构造函数，不允许实例化
	private StaticProperty()
	{
		;
	}

	/**
	 * 获取由propertyName指定的静态常量对象
	 * @param propertyName 指定一个静态常量的字符串<br />
	 * 如org.eclipse.swt.SWT.NONE，表示org.eclipse.swt.SWT类中的静态属性NONE
	 * @return 返回静态常量对象的引用
	 * @throws ClassNotFoundException
	 * @throws SecurityException
	 * @throws NoSuchFieldException
	 * @throws IllegalAccessException 
	 * @throws IllegalArgumentException 
	 */
	public static Object getStaticValue(String propertyName)
	throws ClassNotFoundException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
	{
		int dotIndex = propertyName.lastIndexOf('.');
		String className = propertyName.substring(0, dotIndex);
		String propertyShortName = propertyName.substring(dotIndex + 1);
		Class clazz = Class.forName(className);
		Field property = clazz.getField(propertyShortName);

		return property.get(null);
	}

	/**
	 * 获取由propertyName指定的静态常量值
	 * @param propertyName 指定一个静态常量的字符串<br />
	 * 如org.eclipse.swt.SWT.NONE，表示org.eclipse.swt.SWT类中的静态属性NONE
	 * @return 返回静态常量的整数值
	 * @throws ClassNotFoundException
	 * @throws SecurityException
	 * @throws NoSuchFieldException
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 */
	public static int getStaticIntValue(String propertyName)
	throws ClassNotFoundException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
	{
		Integer integer = (Integer) getStaticValue(propertyName);
		return integer.intValue();
	}
}
